#include "platform.h"

	# size of each hart's stack is 1024 bytes
	# 用于分配一段内存空间 “External Public Uninitialized Block"
	.equ 	STACK_SIZE, 1024
	
	.global _start

	.text
_start:
	# park harts with id != 0让除了0号核的其他核都进入park状态
	csrr t0, mhartid 		# read current hart id
	mv  tp,t0				# save current hart id to tp
	bnez t0,park 			# if hart id != 0, park

	# Setup stacks, the stack grows from bottom to top, so we put the
	# stack pointer to the very end of the stack range.
	slli	t0, t0, 10		# shift left the hart id by 1024-->(for multiple harts)
	la	sp, stacks + STACK_SIZE	# set the initial stack pointer
							# to the end of the first stack space
	add	sp, sp, t0			# move the current hart stack pointer
							# to its place in the stack space

	j	start_kernel		# hart 0 jump to c

park:
	wfi
	j park

	# In the standard RISC-V calling convention, the stack pointer sp
	# is always 16-byte aligned.
.balign 16
stacks:
	.skip	STACK_SIZE * MAXNUM_CPU # allocate space for all the harts stacks

	.end					# End of file